package cn.legend.travel.admin.content.dao.persist.repository.impl;

import cn.legend.travel.admin.content.dao.persist.mapper.ReviewMapper;
import cn.legend.travel.admin.content.dao.persist.repository.IReviewRepository;
import cn.legend.travel.admin.content.pojo.entity.Review;
import cn.legend.travel.admin.content.pojo.vo.ReviewCheckVO;
import cn.legend.travel.admin.content.pojo.vo.ReviewDetailVO;
import cn.legend.travel.common.pojo.vo.PageData;
import cn.legend.travel.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class ReviewRepositoryImpl implements IReviewRepository {
    private final ReviewMapper mapper;

    @Override
    public int changeDisplay(Long id, Integer isDisplay) {
        Review review = new Review();
        review.setId(id);
        review.setIsDisplay(isDisplay);
        return mapper.updateById(review);
    }

    @Override
    public int check(Long id, Integer state) {
        Review review = new Review();
        review.setId(id);
        review.setState(state);
        return mapper.updateById(review);
    }

    @Override
    public PageData<ReviewCheckVO> list(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return PageInfoToPageDataConverter.convert(new PageInfo<>(mapper.list()));
    }

    @Override
    public ReviewDetailVO getDetail(Long id) {
        return mapper.getDetail(id);
    }
}
